SET ANSI_NULLS ON
SET ANSI_WARNINGS ON
GO

IF EXISTS (SELECT 1 FROM sys.Objects WHERE  OBJECT_ID = OBJECT_ID(N'[MD3].[InsertLogMessage]'))
BEGIN				
	DROP PROCEDURE [MD3].[InsertLogMessage]
END
GO
CREATE PROCEDURE [MD3].[InsertLogMessage]
	(
		@Message NVARCHAR(MAX),
		@Severity CHAR(1),
		@ProcedureName NVARCHAR(256) = NULL,
		@ScriptName NVARCHAR(256) = NULL,
		@ErrorNumber INT = NULL  ,
		@ErrorMessage NVARCHAR(MAX) = NULL,
		@ErrorLine		INT = NULL,
		@ErrorState		INT = NULL,
		@ErrorSeverity	INT = NULL
	)
AS
BEGIN 
	
	SET NOCOUNT ON

		INSERT [MD3].[Log]
				(
				 DTime
				,Severity
				,ScriptName
				,ProcName
				,Message
				,ErrorMessage
			   ,ErrorNumber		
			   ,ErrorLine		
			   ,ErrorSeverity	
			   ,ErrorState		
				)
		 SELECT 
				 GETDATE()
				,@Severity
				,@ScriptName
				,@ProcedureName
				,@Message
				,@ErrorMessage
				,@ErrorNumber
				,@ErrorLine
				,@ErrorSeverity
				,@ErrorState
			
		  -----------------------------	
		  --Printing Loggingtext 
		  -----------------------------	

			PRINT @Message
			RETURN 0;




END
GO